package interview;

import java.util.PriorityQueue;

//面试题 17.14. 最小K个数
public class Num17_14_smallestK {
    public int[] smallestK(int[] arr, int k) {
//        PriorityQueue<Integer> queue = new PriorityQueue<>();
//        for (int i = 0; i < arr.length; i++) {
//            queue.offer(arr[i]);
//        }
//        int[]ret=new int[k];
//        for (int i = 0; i < k; i++) {
//            ret[i]=queue.poll();
//        }
//        return ret;

        PriorityQueue<Integer> queue = new PriorityQueue<>();
        for (int i = 0; i < arr.length; i++) {
            queue.offer(arr[i]);
        }
        int []res = new int[k];
        for (int i = 0; i < k; i++) {
            res[i] = queue.poll();
        }
        return res;

    }
}
